import { mvDetail } from "../../API/api"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    src: '',
    danmuList:
      [{
        text: '第 1s 出现的弹幕',
        color: '#ff0000',
        time: 1
      }, {
        text: '第 3s 出现的弹幕',
        color: '#ff00ff',
        time: 3
      }],
    inputValue: '',
    show: false,
    actions: [
      {
        name: '红色',
        color: "#f00"
      },
      {
        name: '蓝色',
        color: "#00f"
      },
      {
        name: "绿色",
        color: '#0f0'
      },
    ],
    color: ""
  },

  select() {
    this.setData({
      show: true
    })
  },
  onClose() {
    this.setData({ show: false });
  },

  onSelect(event) {
    // console.log(event.detail);
    this.setData({
      color: event.detail.color
    })
  },
  start() {
    this.videoContext.play()
  },
  stop() {
    this.videoContext.pause()
  },
  bindButtonTap() {
    const that = this
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      camera: ['front', 'back'],
      success(res) {
        that.setData({
          src: res.tempFilePath
        })
      }
    })
  },
  bindPlayVideo() {
    console.log('1')
    this.videoContext.play()
  },
  bindSendDanmu() {
    this.videoContext.sendDanmu({
      text: this.data.inputValue,
      color: this.data.color
    })
    this.setData({
      inputValue: ""
    })
  },

  videoErrorCallback(e) {
    console.log('视频错误信息:')
    console.log(e.detail.errMsg)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    mvDetail(options.mvid).then(res => {
      // console.log(res);
      this.setData({
        src: res.data.data.url
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.videoContext = wx.createVideoContext('myVideo')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})